﻿Imports GisMapF
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Public Class frmGisResult
    Public FileType As FileType
    Public m_manager As LayerManager
    Public m_Assistant As New Assistant
    Public m_proj As New CAermod.ProjSet
    Private m_ArrGrid(-1) As SDSGridLineLayer
    Private covertLocation As New UTM.Cover
    Private GeoPoint As New UTM.GeoPoint
    Private UtmZone As Integer = 50
    Public Assistant As New Assistant
    ''' <summary>
    ''' 用于保存较老的等值线层的Key，以便于叠加或删除等值线层
    ''' </summary>
    ''' <remarks></remarks>
    Private m_OldContourdKey As String
    ''' <summary>
    ''' 用于保存较老的
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property OldContourdKey() As String
        Get
            Return Me.m_OldContourdKey
        End Get
        Set(ByVal value As String)
            Me.m_OldContourdKey = value
        End Set
    End Property
    Public Sub New(ByVal strProjPath As String)

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        m_manager = New LayerManager(AxMap1, strProjPath)
        AddHandler m_manager.mousePosChanged, AddressOf Me.OnMousePosChanged

    End Sub
    ''' <summary>
    ''' 加载 GIS 各层的方法 
    ''' </summary>
    ''' <param name="t">t = True 时加载各层，t = False 不加载</param>
    ''' <remarks></remarks>
    Public Sub CreateGis(ByVal t As Boolean)
        If t = True Then
            Me.m_manager.UnloadAllLayer() '删除所有图层

            '等值线
            Dim con As New SDSContourLayer("contour")
            con = PublicVal.CommonDrawProperty._Contour.CopyLayerProp
            m_manager.AddLayer(con)
            con.LdescProperty = "等值线"
            ' con.LineWidthProperty = 0.0
            '图例样式
            con.IsLengendTextFormat = True
            con.LTextFormatNum = 0
            '王如建添加的代码----------------
            Me.m_OldContourdKey = "contour"


            '网格()
            Dim grd As SDSGridLineLayer = PublicVal.CommonDrawProperty._grd.CopyLayerProp
            m_manager.AddLayer(grd)
            grd.LdescProperty = "网格"
            '网格样式
            'grd.LineColorProperty = Color.Gray
            

            '坐标轴
            Dim axis As SDSAxisLayer = PublicVal.CommonDrawProperty._axis.CopyLayerProp
            m_manager.AddLayer(axis)

            axis.LdescProperty = "坐标轴"
            
            '建筑物
            Dim layer9 As ESPolygonLayer = PublicVal.CommonDrawProperty._build.CopyLayerProp
            layer9.LdescProperty = "建筑物"
            m_manager.AddLayer(layer9)
            'layer9.LineColorProperty = Color.Teal
            'layer9.LineWidthProperty = 0
            'layer9.FillColorProperty = Color.Teal

            '点源
            Dim cpLayer2 As ESPointLayer = PublicVal.CommonDrawProperty._ppoint.CopyLayerProp
            cpLayer2.LdescProperty = "点源"
            m_manager.AddLayer(cpLayer2)
            'cpLayer2.PointsizeProperty = 6
            'cpLayer2.PointColorProperty = Color.Black
            'cpLayer2.PointtypeProperty = Layer.FtkPointType.ptCircle

            '体源
            Dim layer5 As ESPolygonLayer = PublicVal.CommonDrawProperty._cube.CopyLayerProp
            layer5.LdescProperty = "体源"
            m_manager.AddLayer(layer5)
            'layer5.LineColorProperty = Color.SkyBlue
            'layer5.LineWidthProperty = 2
            'layer5.FillColorProperty = Color.SkyBlue

            '矩形面源
            Dim layer7 As ESPolygonLayer = PublicVal.CommonDrawProperty._rect.CopyLayerProp
            layer7.LdescProperty = "矩形面源"
            m_manager.AddLayer(layer7)
            'layer7.LineColorProperty = Color.Blue
            'layer7.LineWidthProperty = 2
            'layer7.FillColorProperty = Color.Blue

            '多边形源
            Dim layer4 As ESPolygonLayer = PublicVal.CommonDrawProperty._poly.CopyLayerProp
            layer4.LdescProperty = "多边形源"
            m_manager.AddLayer(layer4)
            'layer4.LineColorProperty = Color.Fuchsia
            'layer4.LineWidthProperty = 2
            'layer4.FillColorProperty = Color.Fuchsia

            '圆形面源
            Dim layer6 As ESPolygonLayer = PublicVal.CommonDrawProperty._circle.CopyLayerProp
            layer6.LdescProperty = "圆形面源"
            m_manager.AddLayer(layer6)
            'layer6.LineColorProperty = Color.Blue
            'layer6.LineWidthProperty = 2
            '敞口源
            Dim layer8 As ESPolygonLayer = PublicVal.CommonDrawProperty._exp.CopyLayerProp
            layer8.LdescProperty = "敞口源"
            m_manager.AddLayer(layer8)
            'layer8.LineColorProperty = Color.MediumSpringGreen
            'layer8.LineWidthProperty = 2
            'layer8.FillColorProperty = Color.MediumSpringGreen
            '线源
            Dim layer3 As ESMLineLayer = PublicVal.CommonDrawProperty._pline.CopyLayerProp
            layer3.LdescProperty = "线源"
            m_manager.AddLayer(layer3)

            'layer3.LineWidthProperty = 2
            'layer3.LineColorProperty = Color.Green


            ' 关心点 点层的例子，哈哈
            Dim cpLayer As ESPointLayer = PublicVal.CommonDrawProperty._cpoint.CopyLayerProp
            cpLayer.LdescProperty = "关心点"

            m_manager.AddLayer(cpLayer)
            '关心点样式
            'cpLayer.PointsizeProperty = 6
            'cpLayer.PointColorProperty = Color.Red
            'cpLayer.PointtypeProperty = Layer.FtkPointType.ptTriangleUp

            m_Assistant.m_manager = Me.m_manager
        End If
        Dim MyMainFrm As frmMain = My.Application.ApplicationContext.MainForm
        MyMainFrm.frmAnalyse.Refresh()
    End Sub
    ''' <summary>
    ''' 将公共设置用于当前绘图
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub UseCommonGisSet()
        '等值线
        Dim con As SDSContourLayer
        Me.m_manager.GetLayer(m_OldContourdKey, con)
        con.CopyProp(PublicVal.CommonDrawProperty._Contour)
        '网格()
        Dim grd As SDSGridLineLayer
        Me.m_manager.GetLayer("grid", grd)
        grd.CopyProp(PublicVal.CommonDrawProperty._grd)

        '坐标轴
        Dim axis As SDSAxisLayer
        Me.m_manager.GetLayer("axis", axis)
        axis.CopyProp(PublicVal.CommonDrawProperty._axis)


        '建筑物
        Dim build As ESPolygonLayer
        Me.m_manager.GetLayer("build", build)
        build.CopyProp(PublicVal.CommonDrawProperty._build)

        '点源
        Dim ppoint As ESPointLayer
        Me.m_manager.GetLayer("ppoint", ppoint)
        ppoint.CopyProp(PublicVal.CommonDrawProperty._ppoint)

        '体源
        Dim cube As ESPolygonLayer
        Me.m_manager.GetLayer("cube", cube)
        cube.CopyProp(PublicVal.CommonDrawProperty._cube)


        '矩形面源
        Dim rect As ESPolygonLayer
        Me.m_manager.GetLayer("rect", rect)
        rect.CopyProp(PublicVal.CommonDrawProperty._rect)

        '多边形源
        Dim poly As ESPolygonLayer
        Me.m_manager.GetLayer("poly", poly)
        poly.CopyProp(PublicVal.CommonDrawProperty._poly)


        '圆形面源
        Dim circle As ESPolygonLayer
        Me.m_manager.GetLayer("circle", circle)
        circle.CopyProp(PublicVal.CommonDrawProperty._circle)

        '敞口源
        Dim exp As ESPolygonLayer
        Me.m_manager.GetLayer("exp", exp)
        exp.CopyProp(PublicVal.CommonDrawProperty._exp)

        '线源
        Dim pline As ESMLineLayer
        Me.m_manager.GetLayer("pline", pline)
        pline.CopyProp(PublicVal.CommonDrawProperty._pline)


        ' 关心点 点层的例子，哈哈
        Dim cpoint As ESPointLayer
        Me.m_manager.GetLayer("cpoint", cpoint)
        cpoint.CopyProp(PublicVal.CommonDrawProperty._cpoint)

        Dim MyMainFrm As frmMain = My.Application.ApplicationContext.MainForm
        MyMainFrm.frmAnalyse.Refresh()
    End Sub


    ''' <summary>
    ''' 设置网格
    ''' </summary>
    ''' <param name="Xmin">X 坐标</param>
    ''' <param name="Ymin">Y 坐标</param>
    ''' <param name="xcount">X 轴个数</param>
    ''' <param name="ycount">Y 轴个数</param>
    ''' <param name="xsteep">X 轴步长</param>
    ''' <param name="ysteep">X 轴步长</param>
    ''' <remarks></remarks>
    Public Sub SetGrid(ByVal Xmin As Double, ByVal Ymin As Double, ByVal xcount As Integer, ByVal ycount As Integer, ByVal xsteep As Double, ByVal ysteep As Double)

        Dim grd As SDSGridLineLayer
        Me.m_manager.GetLayer("grid", grd)
        grd.SetGridProperty(Xmin, Ymin, xcount, ycount, xsteep, ysteep)

        Dim axis As SDSAxisLayer

        Me.m_manager.GetLayer("axis", axis)
        axis.SetGridProperty(Xmin, Ymin, Xmin, Ymin, xcount, ycount, xsteep, ysteep)

        Dim MyMainFrm As frmMain = My.Application.ApplicationContext.MainForm
        MyMainFrm.frmAnalyse.Refresh()
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="Grid"></param>
    ''' <param name="nRows">格点数</param>
    ''' <param name="Ymin"></param>
    ''' <param name="Ymax"></param>
    ''' <param name="nCols">格点数</param>
    ''' <param name="Xmin"></param>
    ''' <param name="Xmax"></param>
    ''' <param name="OffsetX"></param>
    ''' <param name="OffsetY"></param>
    ''' <param name="ContourKey"></param>
    ''' <param name="IsSave"></param>
    ''' <param name="dblA"></param>
    ''' <remarks></remarks>
    Public Sub SetContour(ByVal Grid(,) As Double, ByVal nRows As Double, ByVal Ymin As Double, ByVal Ymax As Double _
                          , ByVal nCols As Double, ByVal Xmin As Double, ByVal Xmax As Double, ByVal OffsetX As Double _
                          , ByVal OffsetY As Double, ByVal ContourKey As String, ByVal IsSave As Boolean, ByVal dblA() As Double)
        Dim MyMainFrm As frmMain = My.Application.ApplicationContext.MainForm
        Try

            Dim Index As Integer = 0
            '先删除旧的等值线层
            Me.m_manager.SaveSingleLayer(Me.OldContourdKey)
            Me.m_manager.RemoveLayer(Me.OldContourdKey)
            Me.m_Assistant.SetGrid("grid", Xmin, Ymin, nCols - 1, nRows - 1, (Xmax - Xmin) / (nCols - 1), (Ymax - Ymin) / (nRows - 1), Xmin + AermodProject0.GetOffsetX, Ymin + AermodProject0.GetOffsetY)
            Me.m_Assistant.SetAxis("axis", Xmin, Ymin, nCols - 1, nRows - 1, (Xmax - Xmin) / (nCols - 1), (Ymax - Ymin) / (nRows - 1), Xmin + AermodProject0.GetOffsetX, Ymin + AermodProject0.GetOffsetY)
            '如果用户已经保存了图层，就导入，否则就生成新的。
            If Me.m_manager.IsSingleLayerSaved(ContourKey) And Me.m_manager.IsSingleLayerExist(ContourKey) And IsSave = True Then
                If Me.m_manager.LoadSingleLayer(ContourKey) = True Then '如果载入成功，则返回，否则创建

                    '缺少等值线的UTM坐标设置
                    If Index <= 0 Then
                        Index = PublicVal.BackImage0.InsertImageCollection.Count
                        Index += AermodProject0.Aermap.Control.DataFile.Length
                    End If
                    MyMainFrm.frmAnalyse.m_tree.MoveLayerPosition(Me.m_manager.GetLayerCount - 1, Index)
                    Me.OldContourdKey = ContourKey
                    Exit Sub
                End If
            End If


            '等值线
            Dim con As SDSContourLayer = PublicVal.CommonDrawProperty._Contour.CopyLayerProp
            con.Id = ContourKey
            Me.m_manager.AddLayer(con)
            '缺少等值线的UTM坐标设置
            If Index <= 0 Then
                Index = PublicVal.BackImage0.InsertImageCollection.Count
                Index += AermodProject0.Aermap.Control.DataFile.Length
            End If
            MyMainFrm.frmAnalyse.m_tree.MoveLayerPosition(Me.m_manager.GetLayerCount - 1, Index)
            con.LdescProperty = "等值线"
            '图例样式
            con.IsLengendTextFormat = True
            con.LTextFormatNum = 5
            Me.OldContourdKey = ContourKey

            '等值线
            'Dim con As SDSContourLayer
            'frmM.frmGis_Map.m_manager.GetLayer(ContourFileKey, con)
            con.MyContours.GridPoint = Grid
            con.MyContours.nRow = nRows
            con.MyContours.nCol = nCols

            con.MyContours.Xmin = CInt(Xmin + AermodProject0.GetOffsetX)
            con.MyContours.Xmax = CInt(Xmax + AermodProject0.GetOffsetX)
            con.MyContours.Ymin = CInt(Ymin + AermodProject0.GetOffsetY)
            con.MyContours.Ymax = CInt(Ymax + AermodProject0.GetOffsetY)

            'con.MyContours.Xmin = Xmin
            'con.MyContours.Xmax = Xmax
            'con.MyContours.Ymin = Ymin
            'con.MyContours.Ymax = Ymax


            con.IsShowLegend = True
            Dim lns As List(Of GisMapF.ContourLine)
            Dim cth As New CTHelperV2(con)
            Dim ls As New List(Of Double)
            For i As Integer = 0 To dblA.Length - 1
                ls.Add(dblA(i))
            Next
            If ls.Count > 0 Then
                lns = cth.GetResultList(ls)

                con.CListProperty = lns
            Else
                ls.Add(0)
                lns = cth.GetResultList(ls)
                con.CListProperty = lns
            End If




        Catch ex As Exception
        End Try


        MyMainFrm.frmAnalyse.Refresh()
    End Sub
    Public Sub AddGrid(ByVal gd() As CAermod.GridCart)
        '  m_manager.RemoveLayer("grid")
        For i As Integer = 0 To m_ArrGrid.Length - 1
            m_manager.RemoveLayer(m_ArrGrid(i).LdescProperty)
        Next
        ' ReDim Preserve m_ArrGrid(-1)
        If gd.Length > 0 Then
            Assistant.SetGrid("grid", gd(0).Xinit, gd(0).Yinit _
                                     , gd(0).Xnum - 1, gd(0).Ynum - 1, gd(0).Xdelta, gd(0).Ydelta, gd(0).Xinit + AermodProject0.GetOffsetX, gd(0).Yinit + AermodProject0.GetOffsetY)
            Assistant.SetAxis("axis", gd(0).Xinit, gd(0).Yinit _
                              , gd(0).Xnum - 1, gd(0).Ynum - 1, gd(0).Xdelta, gd(0).Ydelta, gd(0).Xinit + AermodProject0.GetOffsetX, gd(0).Yinit + AermodProject0.GetOffsetY)
            'For i As Integer = 0 To gd.Length - 1
            '    ReDim Preserve m_ArrGrid(m_ArrGrid.Length)

            '    If i = 0 Then

            '        m_ArrGrid(m_ArrGrid.Length - 1) = New SDSGridLineLayer("grid")
            '        m_manager.AddLayer(m_ArrGrid(m_ArrGrid.Length - 1))
            '        m_ArrGrid(m_ArrGrid.Length - 1).LdescProperty = "主网格"
            '        '网格样式
            '        m_ArrGrid(m_ArrGrid.Length - 1).LineColorProperty = Color.Gray

            '        'm_ArrGrid(m_ArrGrid.Length - 1).SetGridProperty(gd(i).Xinit, gd(i).Yinit, gd(i).Xnum, gd(i).Ynum, gd(i).Xdelta, gd(i).Ydelta)
            '    Else
            '        m_ArrGrid(m_ArrGrid.Length - 1) = New SDSGridLineLayer(gd(i).Netid)
            '        m_manager.AddLayer(m_ArrGrid(m_ArrGrid.Length - 1))
            '        m_ArrGrid(m_ArrGrid.Length - 1).LdescProperty = gd(i).Netid
            '        '网格样式
            '        m_ArrGrid(m_ArrGrid.Length - 1).LineColorProperty = Color.Gray

            '        'm_ArrGrid(m_ArrGrid.Length - 1).SetGridProperty(gd(i).Xinit, gd(i).Yinit, gd(i).Xnum, gd(i).Ynum, gd(i).Xdelta, gd(i).Ydelta)
            '    End If
            '    If i = 0 Then
            '        Assistant.SetGrid("grid", gd(i).Xinit + AermodProject0.GetOffsetX, gd(i).Yinit + AermodProject0.GetOffsetY _
            '                          , gd(i).Xnum - 1, gd(i).Ynum - 1, gd(i).Xdelta, gd(i).Ydelta)
            '        Assistant.SetAxis("axis", gd(i).Xinit + AermodProject0.GetOffsetX, gd(i).Yinit + AermodProject0.GetOffsetY _
            '                          , gd(i).Xnum - 1, gd(i).Ynum - 1, gd(i).Xdelta, gd(i).Ydelta)
            '    Else
            '        '由于坐标始终都是从左下角绘制的，所以要减去相应的值
            '        Assistant.SetGrid(m_ArrGrid(m_ArrGrid.Length - 1).LdescProperty, gd(i).Xinit, gd(i).Yinit _
            '                          , gd(i).Xnum - 1, gd(i).Ynum - 1 _
            '                        , gd(i).Xdelta, gd(i).Ydelta _
            '                        , AermodProject0.GetLeftButtomUtmXY.x + (gd(i).Xinit - gd(0).Xinit), AermodProject0.GetLeftButtomUtmXY.y + (gd(i).Yinit - gd(0).Yinit))
            '    End If
            'Next
        End If

        Dim MyMainFrm As frmMain = My.Application.ApplicationContext.MainForm
        MyMainFrm.frmAnalyse.Refresh()
    End Sub
    ''' <summary>
    ''' 更新
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub UpAllSource(ByVal DemFileName As String)
        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        '王如建增加的代码，用于显示地形图-----------------------------------
        Try
            Me.m_Assistant.AddTif(DemFileName, myFrmMain.frmAnalyse.m_tree)
        Catch ex As Exception

        End Try
        For i As Integer = 0 To BackImage0.InsertImageCollection.Count - 1
            With BackImage0.InsertImageCollection(i)
                Dim newFileName As String = AermodProject0.GetProjectPath & "\" & My.Computer.FileSystem.GetName(.FileName)
                Me.m_Assistant.AddImage(.FileNameNoExen, newFileName, New PointF(0, 0), New PointF(.ImageRect.Width, .ImageRect.Height), _
                                                        .LeftBottomPoint, .RightTopPoint, "grid", "axis", PublicVal.AermodProject0.GetOffsetX, PublicVal.AermodProject0.GetOffsetY, myFrmMain.frmAnalyse.m_tree, PublicVal.BackImage0.InsertImageCollection.Count - 1)
            End With
        Next
        '王如建增加的代码结束--------------------------------------------

        Dim list_1 As New List(Of GisMapF.FEntity)
        Dim cpLayer As EditableShapeLayer

        If Me.m_manager.IsSingleLayerExist("cpoint") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim cpLayerTemp As New ESPointLayer("cpoint", New PointTool)
            cpLayerTemp.LdescProperty = "关心点"
            m_manager.AddLayer(cpLayerTemp)
        End If
        Me.Remove("cpoint") '删除所有图层
        m_manager.GetLayer("cpoint", cpLayer)
        For i As Integer = 0 To m_proj.TempAermod.Receptor.DiscCarts.Length - 1

            Dim fe As New GisMapF.FEntity
            fe.desc = m_proj.TempAermod.Receptor.DiscCarts(i).Name
            fe.sn = m_proj.TempAermod.Receptor.DiscCarts(i).ID
            ReDim fe.ptlist(0)
            fe.ptlist(0) = New MapWinGIS.Point
            fe.ptlist(0).x = m_proj.TempAermod.Receptor.DiscCarts(i).Xcoord + AermodProject0.GetOffsetX
            fe.ptlist(0).y = m_proj.TempAermod.Receptor.DiscCarts(i).Ycoord + AermodProject0.GetOffsetY
            list_1.Add(fe)
        Next

        CType(cpLayer, GisMapF.ESPointLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '
        If Me.m_manager.IsSingleLayerExist("ppoint") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim cpLayerTemp As New ESPointLayer("ppoint", New PointTool)
            cpLayerTemp.LdescProperty = "点源"
            m_manager.AddLayer(cpLayerTemp)
        End If
        Me.Remove("ppoint") '删除点源图层
        m_manager.GetLayer("ppoint", cpLayer)
        For i As Integer = 0 To m_proj.TempAermod.Source.PointSources.PointSource.Length - 1
            Dim fe As New GisMapF.FEntity
            fe.desc = m_proj.TempAermod.Source.PointSources.PointSource(i).SourceName
            fe.sn = m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Srcid
            ReDim fe.ptlist(0)
            fe.ptlist(0) = New MapWinGIS.Point

            fe.ptlist(0).x = m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Xs + AermodProject0.GetOffsetX
            fe.ptlist(0).y = m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Ys + AermodProject0.GetOffsetY
            list_1.Add(fe)

        Next

        CType(cpLayer, GisMapF.ESPointLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '
        If Me.m_manager.IsSingleLayerExist("pline") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim layer3 As New ESMLineLayer("pline", New CPlineTool)
            layer3.LdescProperty = "线源"
            m_manager.AddLayer(layer3)
        End If
        Me.Remove("pline") '删除线源图层
        m_manager.GetLayer("pline", cpLayer)

        For i As Integer = 0 To m_proj.TempAermod.Source.LineSources.ArrayLineSources.Length - 1

            Dim fe As New GisMapF.FEntity
            Dim p As Integer = 0
            ReDim fe.ptlist(0)

            fe.desc = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).SourceName
            fe.sn = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).Location.Srcid
            For j As Integer = 0 To m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints.Length - 1
                ReDim Preserve fe.ptlist(p)
                fe.ptlist(p) = New MapWinGIS.Point

                fe.ptlist(p).x = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).x + AermodProject0.GetOffsetX
                fe.ptlist(p).y = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).y + AermodProject0.GetOffsetY
                p += 1

            Next
            list_1.Add(fe)
        Next

        CType(cpLayer, GisMapF.ESMLineLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '

        If Me.m_manager.IsSingleLayerExist("poly") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim layer4 As New ESPolygonLayer("poly", New PolyTool)
            layer4.LdescProperty = "多边形源"
            m_manager.AddLayer(layer4)
        End If
        Me.Remove("poly") '删除多边形面源图层
        m_manager.GetLayer("poly", cpLayer)

        For i As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource.Length - 1

            Dim fe As New GisMapF.FEntity
            Dim p As Integer = 0
            ReDim fe.ptlist(0)

            fe.desc = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).SourceName
            fe.sn = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Srcid

            fe.ptlist(0) = New MapWinGIS.Point
            fe.ptlist(0).x = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Xs + AermodProject0.GetOffsetX
            fe.ptlist(0).y = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Ys + AermodProject0.GetOffsetY

            For j As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length - 1
                ReDim Preserve fe.ptlist(p + 1)
                fe.ptlist(p + 1) = New MapWinGIS.Point

                fe.ptlist(p + 1).x = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).X + AermodProject0.GetOffsetX
                fe.ptlist(p + 1).y = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).Y + AermodProject0.GetOffsetY


                p += 1

            Next
            list_1.Add(fe)
        Next
        CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '
        If Me.m_manager.IsSingleLayerExist("cube") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim layer5 As New ESPolygonLayer("cube", New SquareTool)
            layer5.LdescProperty = "体源"
            m_manager.AddLayer(layer5)
        End If
        Me.Remove("cube") '删除体源图层
        m_manager.GetLayer("cube", cpLayer)

        For i As Integer = 0 To m_proj.TempAermod.Source.VolumeSources.VolumeSource.Length - 1

            Dim fe As New GisMapF.FEntity
            Dim ps As CAermod.VolumeSources
            ps = m_proj.TempAermod.Source.VolumeSources
            Dim p As Integer = 0
            ReDim fe.ptlist(0)

            fe.desc = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).SourceName
            fe.sn = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Srcid
            Dim ptA(3) As MapWinGIS.Point

            ptA(0) = New MapWinGIS.Point
            ptA(0).x = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Xs - m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
            ptA(0).y = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Ys + m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

            ptA(1) = New MapWinGIS.Point
            ptA(1).x = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Xs + m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
            ptA(1).y = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Ys + m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

            ptA(2) = New MapWinGIS.Point
            ptA(2).x = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Xs + m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
            ptA(2).y = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Ys - m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

            ptA(3) = New MapWinGIS.Point
            ptA(3).x = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Xs - m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetX
            ptA(3).y = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Ys - m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Width / 2 + AermodProject0.GetOffsetY

            For j As Integer = 0 To ptA.Length - 1


                ReDim Preserve fe.ptlist(p)
                fe.ptlist(p) = New MapWinGIS.Point

                fe.ptlist(p).x = ptA(j).x
                fe.ptlist(p).y = ptA(j).y

                p += 1

            Next
            list_1.Add(fe)

        Next

        CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '
        If Me.m_manager.IsSingleLayerExist("circle") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim layer6 As New ESPolygonLayer("circle", New CircleToolV3)
            layer6.LdescProperty = "圆形面源"
            m_manager.AddLayer(layer6)
        End If
        Me.Remove("circle") '删除所有圆形面源图层
        m_manager.GetLayer("circle", cpLayer)
        For i As Integer = 0 To m_proj.TempAermod.Source.AreacircSources.AreaCircSource.Length - 1
            Dim fe As New GisMapF.FEntity
            Dim p As Integer = 0

            fe.desc = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).SourceName
            fe.sn = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Srcid
            Dim ptA(1) As MapWinGIS.Point
            ptA(0) = New MapWinGIS.Point
            ptA(0).x = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Xs + AermodProject0.GetOffsetX
            ptA(0).y = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Ys + AermodProject0.GetOffsetY
            Dim rr As Double = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(m_proj.TempAermod.Source.AreacircSources.AreaCircSource.Length - 1).Radius
            Dim ptReturn As New List(Of MapWinGIS.Point)

            For k As Double = 0 To 2 * Math.PI Step Math.PI / 360
                Dim pTemp As New MapWinGIS.Point
                pTemp.x = rr * Math.Cos(k) + ptA(0).x
                pTemp.y = rr * Math.Sin(k) + ptA(0).y
                ptReturn.Add(pTemp)
            Next
            fe.ptlist = ptReturn.ToArray()
            list_1.Add(fe)
           
        Next
        CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '


        If Me.m_manager.IsSingleLayerExist("rect") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim layer7 As New ESPolygonLayer("rect", New RectangleTool)
            layer7.LdescProperty = "矩形面源"
            m_manager.AddLayer(layer7)
        End If
        Me.Remove("rect") '删除矩形面源图层
        m_manager.GetLayer("rect", cpLayer)

        For i As Integer = 0 To m_proj.TempAermod.Source.AreaSources.AreaSource.Length - 1

            Dim fe As New GisMapF.FEntity
            Dim p As Integer = 0
            ReDim fe.ptlist(0)

            fe.desc = m_proj.TempAermod.Source.AreaSources.AreaSource(i).SourceName
            fe.sn = m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Srcid

           
            Dim ptA(3) As MapWinGIS.Point
            ptA(0) = New MapWinGIS.Point
            ptA(0).x = m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Xs + AermodProject0.GetOffsetX
            ptA(0).y = m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Ys + AermodProject0.GetOffsetY
            '设置第2个点
            ptA(1) = New MapWinGIS.Point
            ptA(1).y = ptA(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
            ptA(1).x = ptA(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
            '设置第4个点
            ptA(3) = New MapWinGIS.Point
            ptA(3).y = ptA(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)
            ptA(3).x = ptA(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)

            '设置第3个点
            ptA(2) = New MapWinGIS.Point
            ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
            ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x

            fe.ptlist = ptA
            list_1.Add(fe)
        Next
        CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '



        If Me.m_manager.IsSingleLayerExist("exp") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim layer8 As New ESPolygonLayer("exp", New RectangleTool)
            layer8.LdescProperty = "敞口源"
            m_manager.AddLayer(layer8)
        End If
        Me.Remove("exp") '删除敞口源图层
        m_manager.GetLayer("exp", cpLayer)

        For i As Integer = 0 To m_proj.TempAermod.Source.OpenPitSources.OpenPitSource.Length - 1

            Dim fe As New GisMapF.FEntity
            Dim p As Integer = 0
            ReDim fe.ptlist(0)

            fe.desc = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).SourceName
            fe.sn = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Srcid
            
            Dim ptA(3) As MapWinGIS.Point
            ptA(0) = New MapWinGIS.Point
            ptA(0).x = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs + AermodProject0.GetOffsetX
            ptA(0).y = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys + AermodProject0.GetOffsetY
            '设置第2个点
            ptA(1) = New MapWinGIS.Point
            ptA(1).y = ptA(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
            ptA(1).x = ptA(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
            '设置第4个点
            ptA(3) = New MapWinGIS.Point
            ptA(3).y = ptA(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)
            ptA(3).x = ptA(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)

            '设置第3个点
            ptA(2) = New MapWinGIS.Point
            ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
            ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x

            fe.ptlist = ptA
            list_1.Add(fe)
        Next
        CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)
        '
        list_1.Clear()
        '


        If Me.m_manager.IsSingleLayerExist("build") = False Then '在更新图层之前先看看图层是否存在，如果不存在，需要新建图层
            Dim layer9 As New ESPolygonLayer("build", New PolyTool)
            layer9.LdescProperty = "建筑物"
            m_manager.AddLayer(layer9)
        End If
        Me.Remove("build") '删除建筑物图层
        m_manager.GetLayer("build", cpLayer)

        For i As Integer = 0 To m_proj.TempAermod.Bprm.ArryBldgi.Length - 1

            Dim fe As New GisMapF.FEntity
            Dim p As Integer = 0
            ReDim fe.ptlist(0)

            fe.desc = m_proj.TempAermod.Bprm.ArryBldgi(i).BuildName
            fe.sn = m_proj.TempAermod.Bprm.ArryBldgi(i).BuildStack
            '设置第一个点
            Dim ptA(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1) As MapWinGIS.Point
            For j As Integer = 0 To m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1
                
                ptA(j) = New MapWinGIS.Point
                ptA(j).x = m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x + AermodProject0.GetOffsetX
                ptA(j).y = m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y + AermodProject0.GetOffsetY

            Next


            fe.ptlist = ptA
            list_1.Add(fe)
        Next
        CType(cpLayer, GisMapF.ESPolygonLayer).AddEntityRange(list_1)



        Dim MyMainFrm As frmMain = My.Application.ApplicationContext.MainForm
        '
        list_1.Clear()
        '
        MyMainFrm.frmAnalyse.Refresh()
    End Sub
    ''' <summary>
    ''' 根据主网格返回相对坐标
    ''' </summary>
    ''' <param name="UtmX">绝对坐标X</param>
    ''' <param name="UtmY">绝对坐标Y</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetRelativelyCoordinate(ByVal UtmX As Double, ByVal UtmY As Double) As GisMapF.Point3D
        Return Me.m_Assistant.GetRelativelyCoordinate(UtmX, UtmY, "grid", "axis")
    End Function
    ''' <summary>
    ''' 根据相对坐标求得绝对坐标
    ''' </summary>
    ''' <param name="x">相对坐标X</param>
    ''' <param name="y">相对坐标Y</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetUtmFromRelative(ByVal x As Double, ByVal y As Double) As GisMapF.Point3D
        Return m_Assistant.GetUtmFromRelative(x, y, "grid", "axis")
    End Function
    Private Sub OnMousePosChanged(ByVal x As Double, ByVal y As Double)
        Dim MyMainFrm As frmMain = My.Application.ApplicationContext.MainForm
        MyMainFrm.frmAnalyse.ToolStripLabel1.Text = "UTM:" & FormatNumber(x, 2, TriState.True, TriState.False, TriState.False) & "," & FormatNumber(y, 2, TriState.True, TriState.False, TriState.False)
        'GeoPoint = covertLocation.UtmToGeo(x, y, 32600 + UtmZone)
        'myFrmMain.txtLocation.Text = "经纬度:" + GeoPoint.x.ToString + "  ," + GeoPoint.y.ToString
        'Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        'myFrmMain.ToolStripLabel1.Text = "坐标: " & FormatNumber(x, 2, TriState.True, TriState.False, TriState.False) & " , " & FormatNumber(y, 2, TriState.True, TriState.False, TriState.False)
        Me.Refresh()
    End Sub
    Public Sub Remove(ByVal ln As String)

        Dim cpLayer As EditableShapeLayer
        m_manager.GetLayer(ln, cpLayer)
        If cpLayer IsNot Nothing Then
            cpLayer.RemoveAllEntity()

        End If

    End Sub

    Private Sub frmGisResult_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.AxMap1.MouseWheelSpeed = 0.8
    End Sub

    Private Sub AxMap1_MouseDownEvent(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_MouseDownEvent) Handles AxMap1.MouseDownEvent

    End Sub
End Class